//Initialize functions for uploading file with an optional controller name
function initUploadFile(controller){
	
	$("#alertFileUpload").hide();
	
	$(':file').change(function(){
	    var file = this.files[0];
//	    var name = file.name;
//	    var size = file.size;
	    var type = file.type;
	   
	    console.log(type);
	    
	    //Validation on the file format
	    if(file.type != "text/plain"){
	    	
	    	console.log("erreur de fichier");
	    	
	    	$("#alertFileUploadText").text("Message Erreur a traduire");
	    	
	    	$("#alertFileUpload").addClass("alert-box warning radius");
	    	
	    	if($("#alertFileUpload").hasClass("success")){
	    		$("#alertFileUpload").removeClass("success");
	    	}
	    	
	    	$("#alertFileUpload").show();
	    	
	    	$('#uploadButton').addClass("disabled");
	    }else{
	    	$("#alertFileUpload").hide();
	    	$('#uploadButton').removeClass("disabled");
	    }
	    
	});

	$('#uploadButton').click(function(){
		if(! $("#uploadButton").hasClass("disabled")){
			
			var oMyForm = new FormData();
			  oMyForm.append("file", file.files[0]);
			 
			  $.ajax({
			    url: './uploadFile',
			    data: oMyForm,
			    processData: false,
			    contentType: false,
			    type: 'POST',
			    success: function(data){
			    	$("#alertFileUploadText").text( "Message Success a traduire");
			    	
			    	if($("#alertFileUpload").hasClass("warning")){
			    		$("#alertFileUpload").removeClass("warning");
			    	}
			    	$("#alertFileUpload").addClass( "alert-box success radius");
			    	$("#alertFileUpload").show();
			    	
			    	$('#uploadButton').addClass("disabled");
			    	
			    }
			  });
		}
	});
}

